import request from "@/utils/request";

// 获取算法框架列表
export function getAlgorithmFrameworks() {
  return request({
    url: "/algorithms/list_frameworks",
    method: "post",
  });
}

// 上传算法包
export function uploadAlgorithmPackage(file) {
  const formData = new FormData();
  formData.append("file", file);
  return request({
    url: "/algorithms/upload",
    method: "post",
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}

// 保存完整的算法配置
export function saveAlgorithmConfig(data) {
  return request({
    url: "/algorithms/add",
    method: "post",
    data: data,
  });
}

// 获取所有算法配置
export function listAlgorithms() {
  return request({
    url: "/algorithms/list",
    method: "get",
  });
}

// 搜索算法配置
export function searchAlgorithms(query) {
  return request({
    url: "/algorithms/search/",
    method: "post",
    data: query,
  });
}

// 获取指定算法配置
export function getAlgorithm(algorithmId) {
  return request({
    url: "/algorithms/details/" + algorithmId,
    method: "get",
  });
}

// 更新算法配置
export function updateAlgorithm(algorithmId, data) {
  return request({
    url: "/algorithms/" + algorithmId,
    method: "put",
    data: data,
  });
}

// 删除算法配置
export function delAlgorithm(algorithmId) {
  return request({
    url: "/algorithms/" + algorithmId,
    method: "delete",
  });
}

// 批量删除算法配置
export function delAlgorithmBatch(algorithmIds) {
  return request({
    url: "/algorithms/delete_many",
    method: "delete",
    data: algorithmIds,
  });
}

// 下载算法文件
export function downloadAlgorithm(algorithmId) {
  return request({
    url: "/algorithms/download/" + algorithmId,
    method: "get",
    // responseType: "blob",
  });
}
